package models

import (
	"context"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"token-for-token/global"
)

type User struct {
	Id                        primitive.ObjectID `bson:"_id"`
	Username                  string             `bson:"username"`
	Password                  string             `bson:"password"`
	ApiKey                    string             `bson:"apiKey"`
	Status                    uint               `bson:"status"`
	Email                     string             `bson:"email"`
	MaturityTime              int64              `bson:"maturityTime"`
	TokenForTokenMaturityTime int64              `bson:"tokenForTokenMaturityTime"`
}

func (u *User) GetUserInfoForId(id string) error {
	user := global.DBEngine.Database(global.DbConfig.DbName).Collection("user")
	// 将字符串ID转换为ObjectID
	objID, err := primitive.ObjectIDFromHex(id)
	if err != nil {
		return err
	}
	filter := bson.M{"_id": objID}
	err = user.FindOne(context.Background(), filter).Decode(&u)
	return err
}
